package org.pearl.spring.demo.aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * Created by TD on 2021/8/10
 */
public class MyMethodInterceptor implements MethodInterceptor {


    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {

        Object result = null;
        try {
            System.out.println("方法执行之前：" + methodInvocation.getMethod().toString());
            String name = methodInvocation.getMethod().getName();
            System.out.println(name + "开始执行");
            result = methodInvocation.proceed();
            System.out.println("方法执行之后：" + methodInvocation.getMethod().toString());
            System.out.println("方法正常运行结果：" + result);
            return result;
        } catch (Exception e) {
            System.out.println("方法出现异常:" + e.toString());
            System.out.println("方法运行Exception结果：" + result);
            return result;
        }
    }
}

